package week03.resume.effic;

/**
 * Created by zhangxiaokun on 2018/2/12.
 */
public class TestClone {
    public static int testTime = 100000;
    public static void main(String[] args) {
        testClone();
        testCloneBySerialize();
        testCloneByTranToJson();
    }

    public static void testClone() {
        System.out.println("---------手动复制组装");
        long start = System.currentTimeMillis();
        User user = new User(1001, "zhangsan", 25, new String[]{"海淀区五道口", "回龙观龙腾6区"} );

        for (int i=0; i<testTime; i++) {
            user.clone01();
        }

        long end = System.currentTimeMillis();
        System.out.println("耗时:"+ (end - start));
    }

    public static void testCloneBySerialize() {
        System.out.println("---------通过系列化深度复制");
        long start = System.currentTimeMillis();
        User user = new User(1001, "zhangsan", 25, new String[]{"海淀区五道口", "回龙观龙腾6区"} );

        for (int i=0; i<testTime; i++) {
            user.cloneBySerialize();
        }

        long end = System.currentTimeMillis();
        System.out.println("耗时:"+ (end - start));
    }

    public static void testCloneByTranToJson() {
        System.out.println("---------通过转json 解析，实现深度复制");
        long start = System.currentTimeMillis();
        User user = new User(1001, "zhangsan", 25, new String[]{"海淀区五道口", "回龙观龙腾6区"} );

        for (int i=0; i<testTime; i++) {
            user.cloneByTranToJson();
        }

        long end = System.currentTimeMillis();
        System.out.println("耗时:"+ (end - start));
    }

}
